package com.sxjh.controller.cb;

import cn.hutool.extra.cglib.CglibUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxjh.common.BaseController;
import com.sxjh.config.Authorization;
import com.sxjh.common.Result;
import com.sxjh.entity.Materials;
import com.sxjh.entity.param.Finance4ListParam;
import com.sxjh.entity.param.Finance6ListParam;
import com.sxjh.entity.result.Finance4KhMxResult;
import com.sxjh.entity.result.MaterialListResult;
import com.sxjh.entity.result.MethylAlcoholListResult;
import com.sxjh.service.FinanceService;
import com.sxjh.service.MaterialsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/finance")
@Api(tags = "炭黑厂")
public class FinanceController extends BaseController {

  @Autowired
  private FinanceService financeService;

  @Autowired
  private MaterialsService materialsService;

  @ApiOperation("列表")
  @GetMapping("/list")
  @Authorization("cb.finance.list")
  Result<List<MethylAlcoholListResult>> list2(@Validated Finance6ListParam param) {
    List<MethylAlcoholListResult> list = financeService.list4(param);
    return ok(list);
  }

  @ApiOperation("炭黑物料列表")
  @GetMapping("/materials")
  Result<List<MaterialListResult>> materials() {
    List<Materials> list = materialsService.list(
            new LambdaQueryWrapper<Materials>()
                    .select(Materials::getId, Materials::getName)
                    .eq(Materials::getCategoryId, 8));
    List<MaterialListResult> results = CglibUtil.copyList(list, MaterialListResult::new);
    return ok(results);
  }
  @ApiOperation("炭黑厂产品明细销售报表")
  @GetMapping("/cpMxXs")
//  @Authorization("cb.finance.list")
  Result<List<Finance4KhMxResult>> list3(@Validated Finance4ListParam param) {
    param.setCategoryId(8);
    List<Finance4KhMxResult> list = financeService.list33(param,3);
    return ok(list);
  }
  @ApiOperation("炭黑厂客户综合销售报表")
  @GetMapping("/khMxXs")
//  @Authorization("cb.finance.list")
  Result<List<Finance4KhMxResult>> list4(@Validated Finance4ListParam param) {
    param.setCategoryId(8);
    List<Finance4KhMxResult> list = financeService.list33(param,2);
    return ok(list);
  }
  @ApiOperation("炭黑厂产品综合销售报表")
  @GetMapping("/cpZhXs")
//  @Authorization("cb.finance.list")
  Result<List<Finance4KhMxResult>> list5(@Validated Finance4ListParam param) {
    param.setCategoryId(8);
    List<Finance4KhMxResult> list = financeService.list33(param,5);
    return ok(list);
  }
}
